package main

import (
	"flag"
	"os"
	"time"
	"trader-bot/src"
	"trader-bot/src/alog"
)

func main() {
	var symbol = flag.String("symbol","BTCUSDT","资产类型")
	var interval = flag.String("interval","5m","k线间隔，5m 15m 1h 2h 4h等")
	var limit = flag.Int("limit",99,"均线个数")
	var quality = flag.Float64("quality",0,"资产类型，资产的操作数量，必须是USDT")
	var step = flag.Int("step",3,"分档个数")
	var rate = flag.Float64("rate",1,"低于平均线买入的百分比")
	var profit = flag.Float64("profit",3,"利润率")
	var wait  = flag.Uint("wait",300,"等待时间")
	var cancelTime = flag.Int64("cancel",3600 * 24,"超过多久时间买单没有成交，则以市价卖出")

	var logName  = flag.String("log","trader.log","trader log name")
	flag.Parse()

	alog.InitLog(*logName)

	if *symbol == "" || *interval == "" || *limit == 0 || *quality == 0 {
		alog.Error("can't get pararms.")
		os.Exit(2)
	}

	go func() {
		trader.Cancel(*cancelTime,*symbol)
	}()

	for ;;{
		err := trader.Trader(*symbol,*interval,*limit,*profit,*rate,*step,*quality,*wait)
		if err != nil {
			alog.Errorf("exec failed,",err)
			os.Exit(2)
		}
		time.Sleep(time.Second * 1)
	}


}



